package cn.yup.service.impl;

import cn.yup.domain.Work;
import cn.yup.mapper.WorkMapper;
import cn.yup.query.WorkQueryObject;
import cn.yup.service.IWorkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service   // 表示把该类创建对象交给Spring 管理  @controller
public class WorkServiceImpl implements IWorkService {


    @Autowired //  表示 从spring 容器中 获取 WorkMapper 对象 赋给 WorkMapper 这个变量
    private WorkMapper WorkMapper  ;


    @Override
    public PageInfo findAll(WorkQueryObject queryObject) {
        // PageHelper 插件处理分页
        PageHelper.startPage(queryObject.getCurrentPage(),queryObject.getPageSize());
        // 当前页的数据
       List<Work> Works =  WorkMapper.selectByCondition(queryObject);

        return  new  PageInfo(Works);
    }

    @Override
    public void deleteById(Long id) {
        WorkMapper.deleteById(id) ;
    }

    @Override
    public void saveOrUpdate(Work Work) {
        if (Work.getId() != null) {
            WorkMapper.updateById(Work);
        }
        else {
            WorkMapper.save(Work);
        }
    }

    @Override
    public Work findById(Long id) {
        return WorkMapper.findById(id);
    }

    @Override
    public List<Work> listAll() {
        return WorkMapper.selectAll();
    }

}
